package day0227;

import java.util.Arrays;

public class Test1 {
    public static void main(String[] args) {
        String[]   cards1 = new String[54];
        createCards(cards1);//1.创建54张牌
        shuffleCards(cards1);//2.

        String[] person1 = new String[17];
        String[] person2 = new String[17];
        String[] person3 = new String[17];
        give3Person(cards1,person1,person2,person3);

        System.out.println("person1:"+Arrays.toString(person1));
        System.out.println("person2:"+Arrays.toString(person2));
        System.out.println("person3:"+Arrays.toString(person3));
        System.out.println("剩余3张:"+cards1[cards1.length-1]+","+cards1[cards1.length-2]+","+cards1[cards1.length-3]);
    }

    static void give3Person(String[] cards1, String[] person1, String[] person2, String[] person3) {
        int index=0;
        for (int i = 0; i < person1.length; i++) {
            person1[i]=cards1[index++];
            person2[i]=cards1[index++];
            person3[i]=cards1[index++];
        }
    }

    static void shuffleCards(String[] cards1) {
        //当前第i个元素，和当前第i后边的任意一个元素交换
        for (int i = 0; i < cards1.length; i++) {
            int index=(int)(  (Math.random()* (cards1.length-i) +i));
            //cards1[i] cards1[index]
            String   t=cards1[index];
            cards1[index]=cards1[i];
            cards1[i]=t;
        }
    }

    static void createCards(String[] cards) {
        char[]  types={'♥','♦','♣','♠'};
        String[]  numbers={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
        for (int i = 0; i < types.length; i++) {
            char rank=types[i];
            for (int j = 0; j < numbers.length; j++) {
                String num=numbers[j];
                cards[i*13 + j]= rank+num;
            }
        }
        cards[cards.length-1]="大王";
        cards[cards.length-2]="小王";
        System.out.println(Arrays.toString(cards));
    }
}
